<template>
  <div class="content">
    <div class="wrap">
      <div class="item" @click="handleHref('avatarUrl')">
        <div class="item-left">头像</div>
        <div class="item-right">
          <img
            class="right-pic avatarUrl"
            :src="info.avatar_url == '' ? defaultPic : info.avatar_url"
          />
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('nickName')">
        <div class="item-left">昵称</div>
        <div class="item-right">
          <text class="right-content">{{ info?.nick_name || '' }}</text>
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('realName')">
        <div class="item-left">姓名</div>
        <div class="item-right">
          <text class="right-content">{{ info?.real_name || '' }}</text>
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('age')">
        <div class="item-left">年龄</div>
        <div class="item-right">
          <text class="right-content">{{ info?.age || '' }}</text>
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
    </div>
    <div class="red-txt">必填项</div>
    <div class="wrap">
      <div class="item" @click="handleHref('sex')">
        <div class="item-left">性别</div>
        <div class="item-right">
          <text class="right-content" v-if="info?.gender == 1">男</text>
          <text class="right-content" v-else-if="info?.gender == 2">女</text>
          <text class="right-content" v-else-if="info?.gender == 0"
            >请选择</text
          >
          <text class="right-content" v-else>请选择</text>
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('phone')">
        <div class="item-left">手机号</div>
        <div class="item-right">
          <div class="phone-box">
            <text class="right-content">{{ info?.mobile || '' }}</text>
            <img class="right-icon" src="./../../assets/img/arrow-right.png" />
          </div>
        </div>
      </div>
      <div class="item" @click="handleHref('facePhoto')">
        <div class="item-left">我的人脸照片</div>
        <div class="item-right">
          <img
            class="right-pic"
            :src="info.face_photo == '' ? defaultPic : info.face_photo"
          />
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('healthCard')">
        <div class="item-left">我的健康证</div>
        <div class="item-right">
          <img
            class="right-pic"
            :src="
              info?.health?.image_url == ''
                ? defaultPic
                : info?.health?.image_url
            "
          />
          <img class="right-icon" src="./../../assets/img/arrow-right.png" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'
import wx from 'weixin-js-sdk'
import { postData } from '@/request/request.js'
import { useRoute, useRouter } from 'vue-router'
import defaultPic from '@/assets/img/default-pic.png'

let router = useRouter()
let route = useRoute()
let query = route.query
localStorage.clear()
localStorage.setItem('user_id', query.user_id)
localStorage.setItem('access_token', query.access_token)
localStorage.setItem('open_id', query.open_id)
localStorage.setItem('currentPath', query.currentPath)

let info = ref({})

let wxConfig = () => {
  var url = window.location.href.split('#')[0]
  postData('/wxaccess/oa/jsapi/signature', {
    url: url,
  }).then((res) => {
    wx.config({
      beta: true,
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: 'wxaa5d43496694b970', // 必填，此时是公众号的id.一致
      timestamp: res.datas.timestamp, // 必填，生成签名的时间戳
      nonceStr: res.datas.noncestr, // 必填，生成签名的随机串
      signature: res.datas.signature, // 必填，签名
      jsApiList: ['chooseImage', 'previewImage'], // 必填，需要使用的JS接口列表
      openTagList: ['wx-open-launch-weapp'], // 跳转小程序时
    })
    wx.ready(function () {
      console.log('config is success')
    })
    wx.error(function (err) {
      console.log(JSON.stringify(err))
    })
  })
}

let initInfo = () => {
  postData('/user/info/get', { with_health: 1 }).then((res) => {
    info.value = res.datas
    localStorage.setItem('nickName', info.value?.nick_name || '')
    localStorage.setItem('mobile', info.value?.mobile || '')
  })
}

let handleHref = (key) => {
  if (key == 'avatarUrl') {
    uni.navigateTo({
      url: '/pagesC/myInfo/avatarUrl',
    })
  } else if (key == 'nickName') {
    uni.navigateTo({
      url: '/pagesC/myInfo/nickName',
    })
  } else if (key == 'realName') {
    wx &&
      wx.miniProgram.navigateTo({
        url: '/pagesC/myInfo/realName',
      })
  } else if (key == 'age') {
    wx &&
      wx.miniProgram.navigateTo({
        url: '/pagesC/myInfo/age',
      })
  } else if (key == 'sex') {
    wx &&
      wx.miniProgram.navigateTo({
        url: '/pagesC/myInfo/sex',
      })
  } else if (key == 'phone') {
    uni.navigateTo({
      url: '/pages/loginPhone/loginPhone',
    })
  } else if (key == 'facePhoto') {
    wx &&
      wx.miniProgram.navigateTo({
        url: '/pagesC/myInfo/userFacephoto',
      })
  } else if (key == 'healthCard') {
    uni.navigateTo({
      url: '/pagesC/myInfo/myHealthCard',
    })
  }
}

onMounted(() => {
  // wxConfig()
  initInfo()
})

watch(
  () => route.fullPath,
  () => {
    initInfo()
  }
)
</script>

<style scoped>
.content {
  width: 100%;
  height: 100vh;
  background: #f7f7f8;
  font-size: 0.16rem;
  color: #333;
}
.wrap {
  margin-top: 0.1rem;
}
.red-txt {
  color: #d52424;
  font-size: 0.14rem;
  padding-left: 0.2rem;
  padding: 0.2rem 0 0 0.2rem;
}
.item {
  width: 100%;
  height: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item {
  width: 100%;
  padding: 0 0.2rem;
  box-sizing: border-box;
  height: 0.5rem;
  background: #fff;
  border-bottom: 1px solid #f5f5f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item .item-left {
  width: 30%;
  display: flex;
  align-items: center;
  /* font-size: 0.14rem; */
}

.item .item-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 0.14rem;
}

.right-txt {
}
.right-pic {
  width: 0.26rem;
  height: 0.26rem;
}
.right-icon {
  margin-left: 0.1rem;
  width: 0.16rem;
  height: 0.16rem;
}

/* .avatarUrl {
  border-radius: 50%;
} */

.avatar-wrapper {
  padding: 0;
  width: 0.4rem;
  height: 0.7rem;
  border-radius: 8px;
}

.avatar {
  display: block;
  width: 100%;
  height: 100%;
}

.container {
  display: flex;
}

.phone-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.sub {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0.6rem;
}

.sub button {
  border: none;
  width: 90%;
  height: 0.7rem;
  line-height: 0.7rem;
  display: flex;
  justify-content: center;
  align-items: center;
  background: red;
  border-radius: 0.35rem;
  color: #fff;
  font-weight: 400;
}

.item-right-data {
  padding-right: 0.5rem;
}

.phone-txt {
  font-size: 0.14rem;
}
</style>
